package com.cloud.system.api.provider;

import com.cloud.system.api.bean.NoticeCriteriaBean;
import org.apache.commons.lang.StringUtils;
import org.apache.ibatis.jdbc.SQL;

public class NoticePageProvider {

    public String loadReceiveList(NoticeCriteriaBean noticeCriteriaBean) {
       String LIST_PAGE_SELECT = " t.*, t3.human_id is_read",
                LIST_PAGE_FOMR = " (SELECT t1.* FROM notice t1, notice_send_role t2 WHERE t1.notice_id = t2.notice_id AND t2.role_id = " + noticeCriteriaBean.getRoleId() + ") t";

        if (StringUtils.isNotEmpty(noticeCriteriaBean.getTitle())) {
            LIST_PAGE_FOMR = " (SELECT t1.* FROM notice t1, notice_send_role t2 WHERE t1.notice_id = t2.notice_id AND t2.role_id = " + noticeCriteriaBean.getRoleId() + " and title like '%" + noticeCriteriaBean.getTitle() + "%') t";
        }

        SQL sql = new SQL().SELECT(LIST_PAGE_SELECT).FROM(LIST_PAGE_FOMR);

        sql.LEFT_OUTER_JOIN("(select * from notice_read_human where human_id = " + noticeCriteriaBean.getHumanId() + " ) t3 on t.notice_id = t3.notice_id");

        sql.ORDER_BY(" create_time desc");

        return sql.toString();
    }

    public String loadPublishList(NoticeCriteriaBean noticeCriteriaBean) {
        SQL sql = new SQL().SELECT(" * ").FROM(" notice ");

        sql.WHERE(" create_human_id = " + noticeCriteriaBean.getHumanId());

        if (StringUtils.isNotEmpty(noticeCriteriaBean.getTitle())) {
            sql.WHERE(" title like '%" + noticeCriteriaBean.getTitle() + "%'");
        }

        sql.ORDER_BY(" create_time desc");

        return sql.toString();
    }
}
